/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.war.helpers;

import com.war.config.WebSiteConfig;
import javax.el.ELContext;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author Ambroise
 * @todo Choper le httpRequest pour faire des redirections intelligentes.
 */
@ManagedBean(name="helperNavigation")
@RequestScoped
public class HelperNavigation {

    /**
	 * Get the EL context. See https://cwiki.apache.org/MYFACES/accessing-one-managed-bean-from-another.html
	 */
	private ELContext elContext = FacesContext.getCurrentInstance().getELContext();
	
	/**
	 * Import the UserSession.
	 */
	private WebSiteConfig config = (WebSiteConfig) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "webSiteConfig");
	private HelperDebug debug = (HelperDebug) FacesContext.getCurrentInstance().getApplication().getELResolver().getValue(elContext, null, "helperDebug");
	
    /**
     * Creates a new instance of HelperNavigation
     */
    public HelperNavigation() {
        
    }
    
    public String getPathTemplate(String fileName){
        return this.config.getTemplatesUrl()+fileName+".xhtml";
    }
    
    public String getUrl(String fileName){
        return this.getUrl(fileName, "");
    }
    
    public String getUrl(String fileName, String directory){
        return (directory.equals(""))? this.config.getFacesUrl()+fileName+".xhtml" : this.config.getFacesUrl()+directory+"/"+fileName+".xhtml";
    }
    
    public String getActionUrl(String fileName){
        return "./"+fileName+".xhtml?faces-redirect=true";
    }
    
    public String getActionUrl(String fileName, String directory){
        return (directory.equals(""))? "./"+fileName+".xhtml?faces-redirect=true" : "./"+directory+"/"+fileName+".xhtml?faces-redirect=true";
    }
    
}
